package com.ymatou.iapi.coupon.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONObject;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.coupon.parameter.UseCouponBean;
import com.ymatou.iapi.coupon.parameter.getUsedCouponAmountBean;
import com.ymatou.iapi.coupon.service.getUsedCouponAmountCall;
import com.ymatou.iapi.couponmanage.parameter.CreateCouponBean;
import com.ymatou.iapi.couponmanage.parameter.SellerCreateBatchBean;
import com.ymatou.iapi.couponmanage.service.CreateCouponCall;
import com.ymatou.iapi.couponmanage.service.SellerCreateBatchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponServiceCallServiceV2;
import com.ymttest.business.service.CouponServiceMCallServiceV2;
import com.ymttest.utils.TestDataManager;
/**
*获取用户已经使用的优惠券金额
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getUsedCouponAmount{
	private static getUsedCouponAmountBean bean;
	private static getUsedCouponAmountCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取用户已经使用的优惠券金额");
	}

	@Before
	public void caseUp() {
		bean=new getUsedCouponAmountBean();
		call=new getUsedCouponAmountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_001() {
		Logger.start(true,"正例-获取用户已经使用的优惠券金额-同一批次-领取一次-都是用完");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			int orderid=TestDataManager.getRandomIntNum(5);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CouponServiceCallServiceV2 CouponServiceCallServiceV2 = new CouponServiceCallServiceV2();
			// 平台优惠券
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(1));
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			//领取优惠券
			String couponCode=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			UseCouponBean useCouponBean=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode);
			CouponServiceCallServiceV2.useCoupon(useCouponBean);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add(createCouponCall.getBatchCode());
			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			Logger.comment("amount:"+createcouponBean.getCouponValues().get(0).getDeductionMaxAmount());
			
            String expUsedAmount=createcouponBean.getCouponValues().get(0).getDeductionMaxAmount().stripTrailingZeros().toPlainString();
			Logger.verifyEquals(expUsedAmount, call.getUsedAmount(), "验证节省金额");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证errorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_002() {
		Logger.start(true,"正例-获取用户已经使用的优惠券金额-同一批次-领取两次-都是用完");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			int orderid=TestDataManager.getRandomIntNum(5);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CouponServiceCallServiceV2 CouponServiceCallServiceV2 = new CouponServiceCallServiceV2();
			// 平台优惠券
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(1));
			createcouponBean.setPerUserReceiveMaxCount(2);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			//领取优惠券
			String couponCode1=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			String couponCode2=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			UseCouponBean useCouponBean1=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode1);
			UseCouponBean useCouponBean2=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode2);
			CouponServiceCallServiceV2.useCoupon(useCouponBean1);
			CouponServiceCallServiceV2.useCoupon(useCouponBean2);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add(createCouponCall.getBatchCode());
			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			Logger.comment("amount:"+createcouponBean.getCouponValues().get(0).getDeductionMaxAmount());
			
            String expUsedAmount=createcouponBean.getCouponValues().get(0).getDeductionMaxAmount().stripTrailingZeros().toPlainString();
			Logger.verifyEquals("2", call.getUsedAmount(), "验证节省金额");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证errorCode");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_002_1() {
		Logger.start(true,"正例-买手批次-获取用户已经使用的优惠券金额-同一批次-领取两次-都是用完");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			int orderid=TestDataManager.getRandomIntNum(5);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CouponServiceCallServiceV2 CouponServiceCallServiceV2 = new CouponServiceCallServiceV2();
			// 买手优惠券
			SellerCreateBatchBean sellerCreateBean = couponCallService.setDefaultSellerCreateBatchBean();
			sellerCreateBean.setCouponAmount(new BigDecimal(1));
			sellerCreateBean.setReceiveNumPerUser(2);
			SellerCreateBatchCall sellerCreateBatchCall = couponCallService.SellerCreateBatch(sellerCreateBean);
			//领取优惠券
			String couponCode1=CouponServiceCallServiceV2.receiveCouponInfo(sellerCreateBatchCall.getBatchCode(), userId);
			String couponCode2=CouponServiceCallServiceV2.receiveCouponInfo(sellerCreateBatchCall.getBatchCode(), userId);
			UseCouponBean useCouponBean1=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode1);
			UseCouponBean useCouponBean2=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode2);
			CouponServiceCallServiceV2.useCoupon(useCouponBean1);
			CouponServiceCallServiceV2.useCoupon(useCouponBean2);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add(sellerCreateBatchCall.getBatchCode());
			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			

			Logger.verifyEquals("2", call.getUsedAmount(), "验证节省金额");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证errorCode");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_002_2() {
		Logger.start(true,"正例-1买手批次,1平台批次-获取用户已经使用的优惠券金额-每领取两次-都是用完");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			int orderid=TestDataManager.getRandomIntNum(5);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CouponServiceCallServiceV2 CouponServiceCallServiceV2 = new CouponServiceCallServiceV2();
			//买手优惠券
			SellerCreateBatchBean sellerCreateBean = couponCallService.setDefaultSellerCreateBatchBean();
			sellerCreateBean.setCouponAmount(new BigDecimal(1));
			sellerCreateBean.setReceiveNumPerUser(2);
			SellerCreateBatchCall sellerCreateBatchCall = couponCallService.SellerCreateBatch(sellerCreateBean);
			// 平台优惠券
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(1));
			createcouponBean.setPerUserReceiveMaxCount(2);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			//领取优惠券
			String couponCode1=CouponServiceCallServiceV2.receiveCouponInfo(sellerCreateBatchCall.getBatchCode(), userId);
			String couponCode2=CouponServiceCallServiceV2.receiveCouponInfo(sellerCreateBatchCall.getBatchCode(), userId);
			String couponCode3=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			String couponCode4=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			UseCouponBean useCouponBean1=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode1);
			UseCouponBean useCouponBean2=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode2);
			UseCouponBean useCouponBean3=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode3);
			UseCouponBean useCouponBean4=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode4);
			CouponServiceCallServiceV2.useCoupon(useCouponBean1);
			CouponServiceCallServiceV2.useCoupon(useCouponBean2);
			CouponServiceCallServiceV2.useCoupon(useCouponBean3);
			CouponServiceCallServiceV2.useCoupon(useCouponBean4);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add(sellerCreateBatchCall.getBatchCode());
			batchCodes.add(createCouponCall.getBatchCode());
			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			

			Logger.verifyEquals("4", call.getUsedAmount(), "验证节省金额");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证errorCode");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_003() {
		Logger.start(true,"正例-获取用户已经使用的优惠券金额-两个批次-每个批次领取一次-都是用完");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			int orderid=TestDataManager.getRandomIntNum(5);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CouponServiceCallServiceV2 CouponServiceCallServiceV2 = new CouponServiceCallServiceV2();
			// 平台优惠券1
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(1));
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			//平台优惠券2
			CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(3));
			CreateCouponCall createCouponCall2 = couponCallService.createPlatformCoupon(createcouponBean2);
			//领取优惠券
			String couponCode1=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			String couponCode2=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall2.getBatchCode(), userId);
			UseCouponBean useCouponBean1=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode1);
			UseCouponBean useCouponBean2=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode2);
			CouponServiceCallServiceV2.useCoupon(useCouponBean1);
			CouponServiceCallServiceV2.useCoupon(useCouponBean2);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add(createCouponCall.getBatchCode());
			batchCodes.add(createCouponCall2.getBatchCode());
			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			Logger.comment("amount:"+createcouponBean.getCouponValues().get(0).getDeductionMaxAmount());
			
            String expUsedAmount=createcouponBean.getCouponValues().get(0).getDeductionMaxAmount().stripTrailingZeros().toPlainString();
			Logger.verifyEquals("4", call.getUsedAmount(), "验证节省金额");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证errorCode");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_004() {
		Logger.start(true,"正例-获取用户已经使用的优惠券金额-两个批次-1批次领取一次,1批次领取两次-都是用完");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			int orderid=TestDataManager.getRandomIntNum(5);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CouponServiceCallServiceV2 CouponServiceCallServiceV2 = new CouponServiceCallServiceV2();
			// 平台优惠券1
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(1));
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			//平台优惠券2
			CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(3));
			createcouponBean2.setPerUserReceiveMaxCount(2);
			CreateCouponCall createCouponCall2 = couponCallService.createPlatformCoupon(createcouponBean2);
			//领取优惠券
			String couponCode1=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			String couponCode2=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall2.getBatchCode(), userId);
			String couponCode3=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall2.getBatchCode(), userId);
			UseCouponBean useCouponBean1=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode1);
			UseCouponBean useCouponBean2=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode2);
			UseCouponBean useCouponBean3=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode3);
			CouponServiceCallServiceV2.useCoupon(useCouponBean1);
			CouponServiceCallServiceV2.useCoupon(useCouponBean2);
			CouponServiceCallServiceV2.useCoupon(useCouponBean3);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add(createCouponCall.getBatchCode());
			batchCodes.add(createCouponCall2.getBatchCode());
			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			Logger.comment("amount:"+createcouponBean.getCouponValues().get(0).getDeductionMaxAmount());
			
            String expUsedAmount=createcouponBean.getCouponValues().get(0).getDeductionMaxAmount().stripTrailingZeros().toPlainString();
			Logger.verifyEquals("7", call.getUsedAmount(), "验证节省金额");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证errorCode");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_005() {
		Logger.start(true,"正例-获取用户已经使用的优惠券金额-两个批次-每个批次领取两次-都是用完");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			int orderid=TestDataManager.getRandomIntNum(5);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CouponServiceCallServiceV2 CouponServiceCallServiceV2 = new CouponServiceCallServiceV2();
			// 平台优惠券1
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.setPerUserReceiveMaxCount(2);
			createcouponBean.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(1));
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			//平台优惠券2
			CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean2.setPerUserReceiveMaxCount(2);
			createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(3));
			CreateCouponCall createCouponCall2 = couponCallService.createPlatformCoupon(createcouponBean2);
			//领取优惠券
			String couponCode1=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			String couponCode4=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			String couponCode2=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall2.getBatchCode(), userId);
			String couponCode3=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall2.getBatchCode(), userId);
			UseCouponBean useCouponBean1=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode1);
			UseCouponBean useCouponBean2=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode2);
			UseCouponBean useCouponBean3=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode3);
			UseCouponBean useCouponBean4=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode4);
			
			CouponServiceCallServiceV2.useCoupon(useCouponBean1);
			CouponServiceCallServiceV2.useCoupon(useCouponBean2);
			CouponServiceCallServiceV2.useCoupon(useCouponBean3);
			CouponServiceCallServiceV2.useCoupon(useCouponBean4);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add(createCouponCall.getBatchCode());
			batchCodes.add(createCouponCall2.getBatchCode());
			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			Logger.comment("amount:"+createcouponBean.getCouponValues().get(0).getDeductionMaxAmount());
			
            String expUsedAmount=createcouponBean.getCouponValues().get(0).getDeductionMaxAmount().stripTrailingZeros().toPlainString();
			Logger.verifyEquals("8", call.getUsedAmount(), "验证节省金额");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证errorCode");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_005_1() {
		Logger.start(true,"正例-获取用户已经使用的优惠券金额-两个批次-每个批次领取两次-使用完一张优惠券 ");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			int orderid=TestDataManager.getRandomIntNum(5);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CouponServiceCallServiceV2 CouponServiceCallServiceV2 = new CouponServiceCallServiceV2();
			// 平台优惠券1
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.setPerUserReceiveMaxCount(2);
			createcouponBean.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(1));
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			//平台优惠券2
			CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean2.setPerUserReceiveMaxCount(2);
			createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(3));
			CreateCouponCall createCouponCall2 = couponCallService.createPlatformCoupon(createcouponBean2);
			//领取优惠券
			String couponCode1=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			String couponCode2=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			String couponCode3=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall2.getBatchCode(), userId);
			String couponCode4=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall2.getBatchCode(), userId);
			UseCouponBean useCouponBean1=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode1);
			UseCouponBean useCouponBean2=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode2);
			UseCouponBean useCouponBean3=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode3);
		//	UseCouponBean useCouponBean4=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode4);
			
			CouponServiceCallServiceV2.useCoupon(useCouponBean1);
			CouponServiceCallServiceV2.useCoupon(useCouponBean2);
			CouponServiceCallServiceV2.useCoupon(useCouponBean3);
			//CouponServiceCallServiceV2.useCoupon(useCouponBean4);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add(createCouponCall.getBatchCode());
			batchCodes.add(createCouponCall2.getBatchCode());
			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			Logger.comment("amount:"+createcouponBean.getCouponValues().get(0).getDeductionMaxAmount());

			Logger.verifyEquals("5", call.getUsedAmount(), "验证节省金额");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证errorCode");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_005_2() {
		Logger.start(true,"正例-获取用户已经使用的优惠券金额-两个批次-每个批次可以领取两次-其中1批次领取了一张 ");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			int orderid=TestDataManager.getRandomIntNum(5);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CouponServiceCallServiceV2 CouponServiceCallServiceV2 = new CouponServiceCallServiceV2();
			// 平台优惠券1
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.setPerUserReceiveMaxCount(2);
			createcouponBean.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(1));
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			//平台优惠券2
			CreateCouponBean createcouponBean2 = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean2.setPerUserReceiveMaxCount(2);
			createcouponBean2.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(3));
			CreateCouponCall createCouponCall2 = couponCallService.createPlatformCoupon(createcouponBean2);
			//领取优惠券
			String couponCode1=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			String couponCode2=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			String couponCode3=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall2.getBatchCode(), userId);
			//String couponCode4=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall2.getBatchCode(), userId);
			UseCouponBean useCouponBean1=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode1);
			UseCouponBean useCouponBean2=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode2);
			UseCouponBean useCouponBean3=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode3);
		//	UseCouponBean useCouponBean4=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode4);
			
			CouponServiceCallServiceV2.useCoupon(useCouponBean1);
			CouponServiceCallServiceV2.useCoupon(useCouponBean2);
			CouponServiceCallServiceV2.useCoupon(useCouponBean3);
			//CouponServiceCallServiceV2.useCoupon(useCouponBean4);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add(createCouponCall.getBatchCode());
			batchCodes.add(createCouponCall2.getBatchCode());
			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			Logger.comment("amount:"+createcouponBean.getCouponValues().get(0).getDeductionMaxAmount());

			Logger.verifyEquals("5", call.getUsedAmount(), "验证节省金额");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证errorCode");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_006() {
		Logger.start(true,"正例-获取用户已经使用的优惠券金额-userId为空");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			int orderid=TestDataManager.getRandomIntNum(5);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CouponServiceCallServiceV2 CouponServiceCallServiceV2 = new CouponServiceCallServiceV2();
			// 平台优惠券
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(1));
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			//领取优惠券
			String couponCode=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			UseCouponBean useCouponBean=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode);
			CouponServiceCallServiceV2.useCoupon(useCouponBean);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add(createCouponCall.getBatchCode());
			bean.setBatchCodes(batchCodes);
			//bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			
//            String expUsedAmount=createcouponBean.getCouponValues().get(0).getDeductionMaxAmount().stripTrailingZeros().toPlainString();
			Logger.verifyEquals("1", call.getStatusCode1(), "验证errorCode");		
			Logger.verifyEquals(true, call.getErrorMessage().contains("请传入用户编号"), "验证errorMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_007() {
		Logger.start(true,"正例-获取用户已经使用的优惠券金额-batchCodes为空");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			List<String> batchCodes=new ArrayList();

			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			

			Logger.verifyEquals("1", call.getStatusCode1(), "验证errorCode");		
			Logger.verifyEquals(true, call.getErrorMessage().contains("请传入批次编号列表"), "验证errorMessage");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_008() {
		Logger.start(true,"正例-获取用户已经使用的优惠券金额-两个批次,1批次不存在");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			int orderid=TestDataManager.getRandomIntNum(5);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CouponServiceCallServiceV2 CouponServiceCallServiceV2 = new CouponServiceCallServiceV2();
			// 平台优惠券
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(1));
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			//领取优惠券
			String couponCode=CouponServiceCallServiceV2.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			UseCouponBean useCouponBean=CouponServiceCallServiceV2.setUseCouponBean(userId,orderid, couponCode);
			CouponServiceCallServiceV2.useCoupon(useCouponBean);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add(createCouponCall.getBatchCode());
			batchCodes.add(createCouponCall.getBatchCode()+"11111");
			
			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			Logger.comment("amount:"+createcouponBean.getCouponValues().get(0).getDeductionMaxAmount());
			
            String expUsedAmount=createcouponBean.getCouponValues().get(0).getDeductionMaxAmount().stripTrailingZeros().toPlainString();
			Logger.verifyEquals(expUsedAmount, call.getUsedAmount(), "验证节省金额");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证errorCode");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_009() {
		Logger.start(true,"正例-获取用户已经使用的优惠券金额-一个批次,批次不存在");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add("11111");
			
			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
	
			Logger.verifyEquals("0", JSONObject.fromObject(call.getString("data").toString()).getString("usedAmount"), "验证节省金额");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证errorCode");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUsedCouponAmount_010() {
		Logger.start(true,"正例-获取用户已经使用的优惠券金额-一批次-没有领取一次");
		try {
			int userId=TestDataManager.getRandomIntNum(5);
			int orderid=TestDataManager.getRandomIntNum(5);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CouponServiceCallServiceV2 CouponServiceCallServiceV2 = new CouponServiceCallServiceV2();
			// 平台优惠券
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.getCouponValues().get(0).setDeductionMaxAmount(new BigDecimal(1));
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			
			List<String> batchCodes=new ArrayList();
			batchCodes.add(createCouponCall.getBatchCode());
			bean.setBatchCodes(batchCodes);
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();			
			Logger.comment("amount:"+createcouponBean.getCouponValues().get(0).getDeductionMaxAmount());			

			Logger.verifyEquals("0", call.getUsedAmount(), "验证节省金额");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证errorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}